﻿<?php

    /**
    * @framework : My Framework
    *
    * @author: fatangel26@gmail.com - Nguyễn Bảo Trung.
    *
    */

    error_reporting(E_ALL &~ E_NOTICE);
    include "core/my_controller.php";
	include "core/my_model.php";
	include "config/define.php";

	/*Magic Method in PHP 5, it's very useful*/
	function __autoload($str)
    {
    	$path 	= strtolower($str);

        $params = explode('_',$str);

        switch($params[0])
        {
            case 'model':

                require("models/".$params[0]."_".$params[1].".php");

            break;

            case 'helper':

                require("helpers/".$params[0]."_".$params[1].".php");

            break;
        }

    }

	/*Check exists Module*/
	if(isset($_GET['module']))
	{
		/*Get Module*/
		$controller = $_GET['module'];

		/*CHECK FILE EXISTS*/
		if(file_exists("controllers/".$controller."_controller.php"))
		{
			include "controllers/".$controller."_controller.php";

			$controller = $controller."_controller";
			//echo $controller;
			$control 	= new $controller();

			/*Get Action*/

			/*Check exists Action*/
			if(isset($_GET['action']))
			{
				$action = $_GET['action'];

				/*CHECK EXISTS ACTION*/
				if(!method_exists($control, $action))
				{
					include "controllers/errors_controller.php";

					$controller = "errors_controller";

					$control 	= new $controller();

					$control->index();
				}
				else
				{
					$control->$action();
				}
			}
			else
			{
				/*Default Action*/
				$control->index();
			}
		}
		else
		{
			include "controllers/errors_controller.php";

			$controller = "errors_controller";

			$control 	= new $controller();

			$control->index();

		}
	}
	else
	{
        /*Default Controller*/
		include "controllers/layout_controller.php";

		$control = new layout_controller();

		$control->index();
	}

	/* End of file index.php */
	/* Location: .//D/root/my_framework/index.php */